package com.sunlands.zlcx.usercenter.util;

import com.alibaba.druid.util.StringUtils;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Map;

public class AssertUtil {

    /***
     * 判断是否相等(不严谨方法)
     * @param a
     * @param b
     * @return
     */
    public static boolean equals(Object a,Object b){
        if (a == null) {
            return b == null;
        }else if(!a.getClass().equals(b.getClass())){
            return false;
        }else if(a instanceof String && b instanceof String){
            return a.equals(b);
        }else if(a instanceof Number && b instanceof Number){
            return a.equals(b);
        }else{
            return a.equals(b);
        }
    }

    /***
     * 判断是否不相等(不严谨方法)
     * @param a
     * @param b
     * @return
     */
    public static boolean notEquals(Object a,Object b){
        return !equals(a,b);
    }

    /***
     * 判断对象是否为空
     * @param object
     * @return
     */
    public static boolean isEmpty(Object object){
        if(null == object) {
            return true;
        } else if(object instanceof String && StringUtils.isEmpty(object.toString())) {
            return true;
        } else if(object instanceof Collection && CollectionUtils.isEmpty((Collection)object)) {
            return true;
        } else if(object instanceof Map && CollectionUtils.isEmpty((Map)object)) {
            return true;
        }
        return false;
    }

    /***
     * 判断是否不为空
     * @param object
     * @return
     */
    public static boolean isNotEmpty(Object object){
        return !isEmpty(object);
    }

}
